﻿
#region 程序集引用区
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using SubSonic.DataProviders;
using SubSonic.Extensions;
using System.Linq.Expressions;
using SubSonic.Schema;
using System.Collections;
using SubSonic;
using SubSonic.Repository;
using System.ComponentModel;
using System.Data.Common;
using SubSonic.Query;
using System.Xml;
using System.Xml.Serialization;
using System.Reflection;

//引用实体层
using WebeTerm.Model;
using WebeTerm.Common;
#endregion

namespace WebeTerm.DbProvider{
    /// <summary>
    /// 文 件 名: CommandLogDAL.cs
    /// CLR版本 : v2.0.50727
    /// 作   者 : lijun.hu
    /// 版    权: Copyright @2011 lijun.hu(FORCEN HU) 
    /// 电子邮箱：lijun.hu@shinsoft.net
    /// 说    明: 未定义
    /// 生成日期: 2014年12月5日
    /// </summary>
    public partial class CommandLogDAL:BaseDAL< CommandLog >{
        
        #region 通用查询
        /// <summary>
        /// 查询系统设置
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="pages">分页信息</param>
        /// <returns>系统设置</returns>
        public List< CommandLog > SearchCommandLog(CommandLogQuery queryParam, Pages pages)
        {
            IQueryable< CommandLog > iQuery = QueryCommandLog(queryParam);
            var items = base.SplitPage(iQuery, pages).ToList();
            items.ForEach(l=>{
                { if (l is IModel) { (l as IModel).SetIsLoaded(); } }    
            });
            return items;
        }

        /// <summary>
        /// 计算系统设置数
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <returns>系统设置数</returns>
        public int SearchCommandLogCount(CommandLogQuery queryParam)
        {
            return QueryCommandLog(queryParam).Count();
        } 
        #endregion

        #region 组合查询
        /// <summary>
        /// 设置 未定义 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <returns>未定义</returns>
        public IQueryable< CommandLog > QueryCommandLog(CommandLogQuery queryParam)
        {
            IQueryable<CommandLog> iQuery = All();
            iQuery = QueryCommandLogById(queryParam, iQuery);
            iQuery = QueryCommandLogByConfigId(queryParam, iQuery);
            iQuery = QueryCommandLogByCommandType(queryParam, iQuery);
            iQuery = QueryCommandLogBySendString(queryParam, iQuery);
            iQuery = QueryCommandLogByResultString(queryParam, iQuery);
            iQuery = QueryCommandLogByReceiveDate(queryParam, iQuery);
            return iQuery;
        }
        #endregion
        
        #region 单条件查询
        /// <summary>
        /// 根据设置 未定义 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">未定义 查询</param>
        /// <returns>未定义 查询</returns>
        protected virtual IQueryable< CommandLog > QueryCommandLogById(CommandLogQuery queryParam, IQueryable< CommandLog > iQuery)
        {
            if (queryParam.Id != (long)0)
                iQuery = iQuery.Where(iq => iq.Id == queryParam.Id);
            return iQuery;
        }
        /// <summary>
        /// 根据设置 未定义 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">未定义 查询</param>
        /// <returns>未定义 查询</returns>
        protected virtual IQueryable< CommandLog > QueryCommandLogByConfigId(CommandLogQuery queryParam, IQueryable< CommandLog > iQuery)
        {
            if (queryParam.ConfigId != Guid.Empty)
                iQuery = iQuery.Where(iq => iq.ConfigId == queryParam.ConfigId);
            return iQuery;
        }
        /// <summary>
        /// 根据设置 未定义 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">未定义 查询</param>
        /// <returns>未定义 查询</returns>
        protected virtual IQueryable< CommandLog > QueryCommandLogByCommandType(CommandLogQuery queryParam, IQueryable< CommandLog > iQuery)
        {
            if (!string.IsNullOrEmpty(queryParam.CommandType))
                iQuery = iQuery.Where(iq => iq.CommandType.Contains(queryParam.CommandType.Trim()));
            return iQuery;
        }
        /// <summary>
        /// 根据设置 未定义 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">未定义 查询</param>
        /// <returns>未定义 查询</returns>
        protected virtual IQueryable< CommandLog > QueryCommandLogBySendString(CommandLogQuery queryParam, IQueryable< CommandLog > iQuery)
        {
            if (!string.IsNullOrEmpty(queryParam.SendString))
                iQuery = iQuery.Where(iq => iq.SendString.Contains(queryParam.SendString.Trim()));
            return iQuery;
        }
        /// <summary>
        /// 根据设置 未定义 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">未定义 查询</param>
        /// <returns>未定义 查询</returns>
        protected virtual IQueryable< CommandLog > QueryCommandLogByResultString(CommandLogQuery queryParam, IQueryable< CommandLog > iQuery)
        {
            if (!string.IsNullOrEmpty(queryParam.ResultString))
                iQuery = iQuery.Where(iq => iq.ResultString.Contains(queryParam.ResultString.Trim()));
            return iQuery;
        }
        /// <summary>
        /// 根据设置 未定义 查询
        /// </summary>
        /// <param name="queryParam">条件</param>
        /// <param name="iQuery">未定义 查询</param>
        /// <returns>未定义 查询</returns>
        protected virtual IQueryable< CommandLog > QueryCommandLogByReceiveDate(CommandLogQuery queryParam, IQueryable< CommandLog > iQuery)
        {
            if (queryParam.ReceiveDate != DateTime.MinValue)
                iQuery = iQuery.Where(iq => iq.ReceiveDate == queryParam.ReceiveDate);
            return iQuery;
        }
        #endregion
    }
}    